﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace Mystery.SharePoint
{
	/// <summary>
	/// Extension methods for SPFieldCollection
	/// </summary>
	public static class SPFieldCollectionExtensions
	{
		/// <summary>
		/// Looks for the field with the specified id
		/// </summary>
		/// <param name="fields"></param>
		/// <param name="id">Id of the field we are looking for</param>
		/// <returns>A reference to the field if found, otherwise null</returns>
		public static SPField FindById(this SPFieldCollection fields, Guid id)
		{
			if (fields == null) throw new ArgumentNullException("fields");
			try
			{
				return fields[id];
			}
			catch (Exception)
			{
				return null;
			}
		}
	}
}
